import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Composite;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.util.Timer;
import java.util.TimerTask;

import javax.swing.ImageIcon;

import org.pushingpixels.trident.Timeline;

public class LogoPanel extends GamePanel {

	private Image img = null;
	private float value = 0f;
	private final SoundManager soundManager;
	private final Application application;

	public LogoPanel(Application application, SoundManager soundManager) {
		this.application = application;
		this.soundManager = soundManager;

		final Timeline timeline = new Timeline(this);
		timeline.addPropertyToInterpolate("value", 0.0f, 1f);
		timeline.setDuration(3000);
		timeline.play();

		soundManager.playStartSound();

		Timer timer = new Timer();
		timer.schedule(new SelectionTask(), 3000);

		ImageIcon imageIcon = new ImageIcon(getClass().getResource(
				"images/Picture1.jpg"));
		img = imageIcon.getImage();// ImageIO.read(new File("Picture1.jpg"));

	}

	public void setValue(float newValue) {
		this.value = newValue;
		repaint();
	}

	public void paintComponent(Graphics g) {
		g.setColor(Color.white);
		g.fillRect(0, 0, 1000, 1000);
		Graphics2D g2d = (Graphics2D) g;
		Composite oldComp = g2d.getComposite();

		Composite alphaComp = AlphaComposite.getInstance(
				AlphaComposite.SRC_OVER, value);

		g2d.setComposite(alphaComp);
		if (img != null)
			g2d.drawImage(img, getWidth() / 2 - img.getWidth(null) / 2,
					getHeight() / 2 - img.getHeight(null) / 2, null);
		g2d.setComposite(oldComp);

	}

	class SelectionTask extends TimerTask {

		@Override
		public void run() {
			application.showSelectionPanel();
			soundManager.StartBackground();
		}

	}

}
